package com.usian.admin.controller.v1;


import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.admin.service.AdChannelService;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/AdChannel")

public class AdChannelController implements AdChannelControllerApi {
          @Autowired
          private AdChannelService adChannelService;

    /**
     * 查询  分页  查询条件
     * @param dto 封装dto 传递对象
     * @return 通用返回对象
     */

    @Override
    @PostMapping("/findPage")
    public PageResponseResult findPage(@RequestBody ChannelDto dto) {
        return adChannelService.findPage(dto);
    }

    /**
     * 添加
     * @param adChannel
     * @return
     */
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody  AdChannel adChannel) {
        return adChannelService.saveAdChannel(adChannel);
    }

    /**
     *  根据ID 修改数据
     * @param adChannel 封装对象
     * @return
     */
    @Override
    @PostMapping("/update")
    public ResponseResult update( @RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }


    /**
     *  根据ID 删除数据
     * @param id  传递ID
     * @return 返回结果
     */
    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult del(@PathVariable("id") Integer id) {
        return adChannelService.del(id);
    }

    /**
     *  根据ID 查找
     * @param id 传递参数
     * @return
     */
    @Override
    @GetMapping("/findById/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id) {
        AdChannel adChannel = adChannelService.getById(id);
        return  ResponseResult.okResult(adChannel);
    }

    @GetMapping("/findAll")
    @Override
    public ResponseResult findAll() {
        return adChannelService.findAll();
    }
}



